/**
 * 公共全局状态
 */

const state = {
  // 相机信息
  camera: {},
  // 图层信息
  layers: {}
}

const mutations = {
  // 设置图层组
  setLayers: (state, opt) => {
    const { id, layer } = opt
    if (id && layer) {
      state.layers = Object.freeze({ ...state.layers, id: layer })
    }
  },
  removeLayerById: (state, k) => {
    const temp = {}
    Object.keys(state.layers).forEach((lk) => {
      if (lk !== k) {
        temp[lk] = state.layers[lk]
      }
    })
    state.layers = Object.freeze({ ...temp })
  },
  removeAllLayers: (state) => {
    state.layers = {}
  },
  // 设置相机信息
  setCamera: (state, opt) => {
    state.camera = Object.freeze({ ...opt })
  }
}

const actions = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
